package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class AppConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/editor.md/**")
                .excludePathPatterns("/img/**")
                .excludePathPatterns("/images/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/reg.html")
                .excludePathPatterns("/blog_list.html")
                .excludePathPatterns("/blog_content.html")
                .excludePathPatterns("/froget_pwd.html")
                .excludePathPatterns("/art/detail")
                .excludePathPatterns("/user/getuserbyid")
                .excludePathPatterns("/art/incr-rcount")
                .excludePathPatterns("/art/listbypage")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/art/logout")
                .excludePathPatterns("/user/reg")
                .excludePathPatterns("/comments/getcomments")
                .excludePathPatterns("/comments/addgcount")
                .excludePathPatterns("/comments/addbcount")
                .excludePathPatterns("/comments/addgcount2")
                .excludePathPatterns("/comments/addbcount2")
                .excludePathPatterns("/comments/getreplaycomments")
                .excludePathPatterns("/comments/addreplaycomments")
                .excludePathPatterns("/comments/addreplaycomments2")
                .excludePathPatterns("/comments/delcomments")
                .excludePathPatterns("/comments/delcomments2")
                .excludePathPatterns("/user/getusernamebyuid")
                .excludePathPatterns("/user/getusernamebyrid")
                .excludePathPatterns("/personal/forgetpwd")
                .excludePathPatterns("/personal/getsafequestion1")
                .excludePathPatterns("/user/getcode")
                .excludePathPatterns("/art/getartcount")
                .excludePathPatterns("/art/addgoodcount")
                .excludePathPatterns("/art/addbadcount")
                .excludePathPatterns("/comments/addcomments");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
                .addResourceHandler("/images/**")
                .addResourceLocations("file:C:/images/"); //本机路径
//                .addResourceLocations("file:/root/photo/"); //服务器绝对地址

    }


}
